package com.fasttreatment.zzr.demo.utils;

import android.view.View;

/**
 * Created by zzr on 17/1/20.
 */

public abstract class OnRepeatClickListener implements View.OnClickListener {
    // 两次点击按钮之间的点击间隔不能少于1000毫秒
    private static final int CLICK_DELAY_TIME = 1000;
    private static long lastClickTime;

    public abstract void onRepeatClick(View v);

    @Override
    public void onClick(View view) {
        long curClickTime = System.currentTimeMillis();
        if ((curClickTime - lastClickTime) >= CLICK_DELAY_TIME) {
            // 超过点击间隔后再将lastClickTime重置为当前点击时间
            lastClickTime = curClickTime;
            onRepeatClick(view);
        }
    }
}
